import { ref, watch, computed, type Ref } from 'vue';

/**
 * @description 首屏加载 loading
 * @author wfd
 * @date 2022/9/26 19:01
 * @example
 * @param args
 * @returns {any}
 */
export function useLoading (...args: Ref<boolean>[]) {
  const args_length = args.length;
  const loadingIndex = ref(0);
  
  watch(
    () => args,
    () => {
      args.forEach((item, index) => {
        if (item.value) {
          loadingIndex.value++;
          args.splice(index, 1);
        }
      });
    },
    {
      deep: true,
      immediate: true
    }
  );
  
  const isLoading = computed(() => {
    return loadingIndex.value !== args_length;
  });
  
  return isLoading;
}
